{{extend "base.html"}}

{{block body_tag}}
<body class="gray-bg">
{{end}}

{{block content}}

    <div class="wrapper wrapper-content animated fadeInRight">

    <!-- Panel Other -->
        <div class="ibox float-e-margins">

            <div class="ibox-content">
                <div class="row row-lg">

                    <div class="col-sm-12">
                        <!-- Example Events -->
                        <div class="example-wrap">

                            <div class="example">

                                <div class="btn-group hidden-xs" id="toolbar" role="group">

                                    <button type="button" id="unlock" name="unlock" class="btn btn-outline btn-default">
                                        <i class="fa fa-unlock" aria-hidden="true">解锁</i>
                                    </button>
                                    <button type="button" id="refresh" name="refresh" class="btn btn-outline btn-default">
                                        <i class="glyphicon glyphicon-refresh" aria-hidden="true">刷新</i>
                                    </button>
                                </div>

                                <table  id="table"
                                        data-toggle="table" 
                                        data-url="/myuserpost/user?locked=1" 
                                         data-height="726"
                                        {{#支持手机端}}
                                        data-mobile-responsive="true"
                                        data-toolbar="#toolbar"
                                        {{#搜索框}}
                                        data-search="true"
                                        {{#排序}}
                                        data-sort-name="id"
                                        data-sort-order = "desc"
                                        {{#服务端分页}}
                                        data-side-pagination="server"
                                        data-pagination="true"
                                        data-page-size="16"
                                        data-page-list="[16, 50, 100, All]"
                                        >
                                    <thead>
                                        <tr>
                                            <th data-field="state" data-checkbox="true"></th>
                                            <th data-field="id">ID</th>
                                            <th data-field="username" data-sortable="true">用户名</th>
                                            <th data-field="nickname" data-sortable="true">真实姓名</th>
                                            <th data-field="email">邮箱</th>
                                            <th data-field="mobile">移动电话</th>
                                            <th data-field="date_join" data-sortable="true">注册时间</th>
                                            <th data-field="locked" data-sortable="true">登录状态</th>
                                        </tr>
                                    </thead>
                                </table>
                                

                            </div>
                        </div>
                        <!-- End Example Events -->
                    </div>
                </div>
            </div>
        </div>
        <!-- End Panel Other -->
        
    </div>
    {{end}}
    
    {{block after_footer}}
    
    <script>
    
        var $table = $('#table');
        var $buttonrefresh = $('#refresh');
        var $buttonunlock = $('#unlock');


        $(function () {

            //隐藏ID字段
            $table.bootstrapTable('hideColumn', 'id');

            //刷新
            $buttonrefresh.click(function () {
                $table.bootstrapTable('refresh');
                //重置搜索，搜索为空则无反应
                //$table.bootstrapTable('resetSearch');
            });

            //解锁
            $buttonunlock.click(function () {
                var ids = $.map($table.bootstrapTable('getSelections'), function (row) {
                    return row.id;
                });
                
                if(ids.length >= 1){
                    swal({
                        title: "您确定要解除用户锁定吗",
                        text: "解除用户锁定后允许用户登录！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "解锁",
                        cancelButtonText: "取消",
                        closeOnConfirm: false
                    }, function () {
                        $.ajax({
                            type:"POST",
                            url : '/myuser/userunlocklogin',
                            data : {
                                id : ids.join(",")
                            },
                            dataType : 'json',
                            success : function(d) {
                                if (d.status == '200'){
                                    $table.bootstrapTable('refresh');
                                    swal("解锁成功！", "您已经解锁这些用户登录。", "success");
                                }else{
                                    swal("解锁失败！", d.msg, "error");
                                }
                            }
                        });
                    });
                }else{
                    swal("提示", "请选择要解锁的用户！", "error");
                }
            });

        });

    </script>
    {{end}}
